home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 38 / Amiga Format CD38 (1999-03-15)(Future Publishing)(GB)(Track 1 of 3)[!][issue 1999-04].iso / -seriously_amiga- / programming / other / cyberxxxsrc / decoder / txt / decoderle.c < prev    next >
C/C++ Source or Header  |  1999-02-08  |  3KB  |  148 lines

  1. /*
  2. sc:c/sc opt txt/DecodeRLE.c
  3. */
  4.  
  5. #include "Decode.h"
  6. #include "YUV.h"
  7. #include "Utils.h"
  8. #include "GlobalVars.h"
  9.  
  10. struct RLEData {
  11.   ulong dummy;
  12. };
  13.  
  14. /* /// "DecodeRLE8toRGB()" */
  15. __asm void DecodeRLE8toRGB(REG(a0) uchar *from,
  16.                            REG(a1) uchar *to,
  17.                            REG(d0) ulong width,
  18.                            REG(d1) ulong height,
  19.                            REG(d2) ulong encSize,
  20.                            REG(a2) struct RLEData *spec)
  21. {
  22.   long x, y;
  23.   uchar *iptr;
  24.   ulong mod, opcode, d;
  25.   ulong rowDec=width*2*4;
  26.  
  27.   x=0;
  28.   y=height-1;
  29.   while (y>=0) {
  30.     mod=*from++;
  31.     opcode=*from++;
  32.     if (mod==0x00) {
  33.       if (opcode==0x00) {
  34.         while (x>width) { x-=width; y--; };
  35.         x=0;
  36.         y--;
  37.       } else if (opcode==0x01) {
  38.         y=-1;
  39.       } else if (opcode==0x02) {
  40.         ulong yskip, xskip;
  41.         xskip=*from++;
  42.         yskip=*from++;
  43.         x+=xskip;
  44.         y-=yskip;
  45.       } else {
  46.         long cnt=opcode;
  47.         while (x>=width) { x-=width; y--; };
  48.         iptr=(to+(y*width+x)*4);
  49.         while (cnt--) {
  50.           if (x>=width) {
  51.             x-=width;
  52.             y--;
  53.             iptr-=rowDec; /* iptr=(to+(y*width+x)); */
  54.           }
  55.           d=*from++;
  56.           Idx332ToRGB(d,iptr[1],iptr[2],iptr[3]);
  57.           iptr+=4;
  58.           x++;
  59.         }
  60.         if(opcode & 0x01) from++;
  61.       }
  62.     } else {
  63.       long color, cnt;
  64.       while (x>=width) { x-=width; y--; };
  65.       cnt=mod;
  66.       color=opcode;
  67.       iptr=(to+(y*width+x)*4);
  68.       while (cnt--) {
  69.         if (x>=width) {
  70.           x-=width;
  71.           y--;
  72.           iptr-=rowDec; /* iptr=(to+(y*width+x)); */
  73.         }
  74.         Idx332ToRGB(color,iptr[1],iptr[2],iptr[3]);
  75.         iptr+=4;
  76.         x++;
  77.       }
  78.     }
  79.   }
  80. }
  81. /* \\\ */
  82.  
  83. /* /// "DecodeRLE8to332()" */
  84. __asm void DecodeRLE8to332(REG(a0) uchar *from,
  85.                            REG(a1) uchar *to,
  86.                            REG(d0) ulong width,
  87.                            REG(d1) ulong height,
  88.                            REG(d2) ulong encSize,
  89.                            REG(a2) struct RLEData *spec)
  90. {
  91.   long x, y;
  92.   uchar *iptr;
  93.   ulong mod, opcode;
  94.  
  95.   x=0;
  96.   y=height-1;
  97.   while (y>=0) {
  98.     mod=*from++;
  99.     opcode=*from++;
  100.     if (mod==0x00) {
  101.       if (opcode==0x00) {
  102.         while (x>width) { x-=width; y--; };
  103.         x=0;
  104.         y--;
  105.       } else if (opcode==0x01) {
  106.         y=-1;
  107.       } else if (opcode==0x02) {
  108.         ulong yskip, xskip;
  109.         xskip=*from++;
  110.         yskip=*from++;
  111.         x+=xskip;
  112.         y-=yskip;
  113.       } else {
  114.         long cnt=opcode;
  115.         while (x>=width) { x-=width; y--; };
  116.         iptr=(to+(y*width+x));
  117.         while (cnt--) {
  118.           if (x>=width) {
  119.             x-=width;
  120.             y--;
  121.             iptr-=(width*2); /* iptr=(to+(y*width+x)); */
  122.           }
  123.           *iptr++=remap[*from++];
  124.           x++;
  125.         }
  126.         if(opcode & 0x01) from++;
  127.       }
  128.     } else {
  129.       long color, cnt;
  130.       while (x>=width) { x-=width; y--; };
  131.       cnt=mod;
  132.       color=remap[opcode];
  133.       iptr=(to+(y*width+x));
  134.       while (cnt--) {
  135.         if (x>=width) {
  136.           x-=width;
  137.           y--;
  138.           iptr-=(width*2); /* iptr=(to+(y*width+x)); */
  139.         }
  140.         *iptr++=color;
  141.         x++;
  142.       }
  143.     }
  144.   }
  145. }
  146. /* \\\ */
  147.  
  148.